<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./react_dom/react/react17.development.js"></script>
    <script src="./react_dom/react/react-dom17.development.js"></script>
    <script src="./react_dom/react/babel.min.js"></script>
</head>

<body>
    <div id="main"></div>
    <script type="text/babel">
        class Com extends React.Component {
            constructor(){
                // 调用父类中的constructor,直接执行父类中的所有内容
                // super必须调用
                super();
                console.log(this);
                console.log(this.state);
                this.state={ 
                    num:100
                }

            }
            render() {
                return (<div>
                    <h2>这是com组件</h2>
                    <p>{this.state.num}</p>
                    <button onClick={this.updatanum}>点击更改num</button>
                    <ComTwo title='标题'/>
                </div>)
            }

            updatanum(){
                // this是当前组件对象

                // setState()函数更改state对象内属性的值
                //
                console.log('=====',this);

                this.state({
                    num:this.state.num +10,
                })
            }
        }
        class ComTwo extends React.Component {
            render() {
                //
                console.log(this.props);
                return (<div></div>)
            }
        }
        ReactDOM.render(<Com />, document.getElementById("main"))
    </script>
</body>

</html>